﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CompanyInfo.aspx.cs" Inherits="BEGDC.CC.Web.CIS2.Domestic.CompanyInfo" %>

<%@ Register Src="../../UserControls/Pager.ascx" TagName="Pager" TagPrefix="cc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="../../css/global.css" rel="stylesheet" type="text/css" />
    <link href="../../css/content/entity.css" rel="stylesheet" type="text/css" />
    <link href="../../css/content/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
    <link href="../../css/main.css" rel="stylesheet" type="text/css" />

    <script src="../../js/jquery-1.4.4.min.js" type="text/javascript"></script>

    <script src="../../js/jquery-ui.min.js" type="text/javascript"></script>

    <script src="../../js/entity.js.aspx" type="text/javascript"></script>

    <style type="text/css">
        .widthInfo input
        {
            width: 300px;
        }
        .tablestyle2 input[type="text"]
        {
            height: 14px;
            padding-top: 2px;
            color: #3a3a3a;
            font-size: 100%;
            width: 300px;
            border: 1px solid #ccc;
        }
    </style>

    <script type="text/javascript">
        $(function() {
            $(".add-customer").appendTo(".entity-action2");
            $(".view-oc").appendTo(".entity-action2");
            $(".item-province").val($(".item-province").attr("u"));
            $(".item-category").val($(".item-category").attr("u"));
            var admin = "<%=IsDomenticAdmin %>";
            if (admin == "yes") {
                $("#dvCompany_repPCAT").hide();
                $("#dvCompany_dlPCAT").addClass("entity-selects2-check");
            }
            if (admin == "no") {
                $("#dvCompany_dlPCAT").hide();
                $(".pcatfield").addClass("entity-radios-check");
            }
            if (admin == "") {
                $(".countryfield").addClass("entity-radios-check");
            }
            $(".show-check").each(function() {
                var te = $(this).parent().prev();
                if (te.text().indexOf('*') == -1)
                    te.append("<font style='color: red'>*&nbsp;</font>");
            });
            String.prototype.contains = function(it) { return this.indexOf(it) != -1; };

            $(".check-name").bind("change", function() {
                var companyName = $(".check-name").val();
                var roles = '<%=GetRoleIDs() %>';
                if (companyName != "") {
                    params = '{name:"' + companyName + '",roles:"' + roles + '"}'
                    $.ajax({
                        type: "POST",
                        url: "CompanyInfo.aspx/CheckCompanyName",
                        data: params,
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        success: function(result) {
                            var checkresult = result.d;
                            if (checkresult == "0")
                                $("#name_identity").text("");
                            if (checkresult == "1") {
                                $("#name_identity").text("[名称重复!]");
                            }
                        },
                        error: function(xhr, msg, e) {
                            alert("error");
                        }
                    });
                }

            });
            //for task 844 : Company页面DetailsView的Create按钮文字调整
            $("td.entity-action2 input.entity-add").val("Create a Company");
            $("td.entity-action2 input.entity-add").attr("title", "Create a company (添加公司)");

        });
    </script>

</head>
<body>
    <form runat="server">
    <div class="mainbox">
        <div class="sitemapbox">
            <div id="info" class="sitemap">
                &nbsp;&raquo;&nbsp;Administration&nbsp;&raquo;&nbsp;Company Info
            </div>
        </div>
        <table cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    <!--tab区域-->
                    <div class="tabbox purplebg_dark">
                        <ul class="tabpos">
                            <li><span class="tab_active">
                                <%=Resources.PageTitles.CompanyManagement%></span></li>
                        </ul>
                    </div>
                    <div class="formbox">
                        <span class=" float_lft">
                            <div class="formbox_float_lft">
                                <asp:Button ID="BtnAdd" runat="server" CssClass="entity-add" />
                            </div>
                            <div class="formbox_float_rgt" style="display: none">
                                <asp:Panel ID="CriteriaPanel" runat="server" Style="display: none">
                                    <label>
                                        区域:</label>
                                    &nbsp;<asp:DropDownList ID="ddlArea" runat="server" OnLoad="ddlArea_Load" />
                                </asp:Panel>
                                <asp:TextBox ID="SearchText" runat="server" CssClass="txtbox width140 entity-search-text"
                                    ToolTip="Company Name"></asp:TextBox>
                                <asp:Button ID="Searchbtn" runat="server" CssClass="entity-search" />
                                <asp:Button ID="Cleanbtn" runat="server" CssClass="entity-clear" />
                            </div>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
        <table width="100%" id="Table1" cellspacing="0" cellpadding="0" border="0">
            <tbody>
                <tr>
                    <td>
                        <asp:GridView ID="gvCompany" runat="server" AllowPaging="True" AllowSorting="True"
                            AutoGenerateColumns="False" DataKeyNames="CompanyID" DataSourceID="edsCompany"
                            CssClass="tablestyle">
                            <RowStyle CssClass="tbody" />
                            <HeaderStyle CssClass="thead" ForeColor="#ffffff" />
                            <Columns>
                                <asp:TemplateField HeaderText="Company Name<br/>公司名称" SortExpression="Name">
                                    <ItemTemplate>
                                        <a href="CustomerInfo.aspx?CID=<%#Eval("CompanyID") %>">
                                            <%#Eval("Name") %></a>
                                    </ItemTemplate>
                                    <ItemStyle Width="27%" />
                                </asp:TemplateField>
                                <asp:BoundField DataField="Address" HeaderText="Address<br/>地址" SortExpression="Address"
                                    HtmlEncode="false" />
                                <asp:BoundField DataField="Zip" HeaderText="Zip Code<br/>邮编" SortExpression="Zip"
                                    AccessibleHeaderText="gvZip" HtmlEncode="false" ItemStyle-Width="10%" />
                                <asp:TemplateField HeaderText="PCAT<br/>省/大客户" AccessibleHeaderText="gvPCATs">
                                    <ItemTemplate>
                                        <asp:Repeater runat="server" DataSource='<%# GetPCATs(EvalX("PCATs")) %>'>
                                            <ItemTemplate>
                                                <%#Eval("Province.Name")%><%#Eval("Category.Name")%>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </ItemTemplate>
                                    <ItemStyle Width="10%" />
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Editor<br/>编辑人" SortExpression="LastModifyBy.EmployeeNo">
                                    <ItemTemplate>
                                        <asp:Label runat="server" Text='<%#Eval("LastModifyBy.NameEN")%>' />
                                    </ItemTemplate>
                                    <ItemStyle Width="10%" />
                                </asp:TemplateField>
                                <asp:ActionField HeaderText="Action<br />操作" HeaderStyle-CssClass="entity-action"
                                    ShowDisableButton="true" ShowModifyButton="true" ShowViewButton="true" ItemStyle-Width="7%" />
                            </Columns>
                            <PagerTemplate>
                                <cc:Pager runat="server" />
                            </PagerTemplate>
                        </asp:GridView>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:DetailsView ID="dvCompany" runat="server" DataSourceID="edsCompany" AutoGenerateRows="False"
                            DataKeyNames="CompanyID" EnableModelValidation="True" Visible="False" CssClass="tablestyle2"
                            Width="800">
                            <HeaderStyle CssClass="tablestyle2_Title"></HeaderStyle>
                            <HeaderTemplate>
                                <%=Resources.PageTitles.CompanyManagement%>
                            </HeaderTemplate>
                            <FieldHeaderStyle CssClass="tablestyle2_tdTitle" Width="180" />
                            <Fields>
                                <asp:BoundField DataField="CompanyID" Visible="false" ReadOnly="true" />
                                <asp:CustomizeBoundField DataField="Name" HeaderText="Company Name (公司名称)" ItemStyle-CssClass="entity-notnull-check widthInfo"
                                    AccessibleHeaderText="CompanyNameReadOnly" Visible="false" ReadOnly="true" />
                                <asp:CustomizeTemplateField HeaderText="Company Name (公司名称)" ItemStyle-CssClass="entity-notnull-check entity-length-check widthInfo"
                                    AccessibleHeaderText="CompanyName" MaxLength="50">
                                    <ItemTemplate>
                                        <label>
                                            <%#Eval("Name") %></label>
                                    </ItemTemplate>
                                    <InsertItemTemplate>
                                        <input type="text" name="company-name" class="check-name" />
                                        <font id="name_identity" style="color: Red;"></font>
                                    </InsertItemTemplate>
                                    <EditItemTemplate>
                                        <input type="text" name="company-name" class="check-name" value='<%#Eval("Name") %>' />
                                        <font id="name_identity" style="color: Red;"></font>
                                    </EditItemTemplate>
                                </asp:CustomizeTemplateField>
                                <asp:CustomizeBoundField DataField="Address" HeaderText="Address (地址)" AccessibleHeaderText="Address"
                                    ItemStyle-CssClass="entity-length-check widthInfo" MaxLength="100" />
                                <asp:CustomizeBoundField DataField="Tel" HeaderText="Telephone (电话)" AccessibleHeaderText="Tel"
                                    ItemStyle-CssClass="entity-length-check widthInfo" MaxLength="50" />
                                <asp:CustomizeBoundField DataField="Fax" HeaderText="Fax (传真)" AccessibleHeaderText="Fax"
                                    ItemStyle-CssClass="entity-length-check widthInfo" MaxLength="50" />
                                <asp:CustomizeBoundField DataField="Website" HeaderText="Website (网址)" AccessibleHeaderText="Website"
                                    ItemStyle-CssClass="entity-length-check widthInfo" MaxLength="100" />
                                <asp:CustomizeBoundField DataField="Zip" HeaderText="Zipcode (邮编)" AccessibleHeaderText="Zip"
                                    ItemStyle-CssClass="entity-length-check widthInfo" MaxLength="50" />
                                <asp:TemplateField HeaderText="Province\CAT (省\大客户)" AccessibleHeaderText="PCATs"
                                    ItemStyle-CssClass="pcatfield">
                                    <ItemTemplate>
                                        <asp:Repeater runat="server" DataSource='<%# GetPCATs(EvalX("PCATs")) %>'>
                                            <ItemTemplate>
                                                <div>
                                                    <%#Eval("Province.Name")%><%#Eval("Category.Name")%>
                                                </div>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </ItemTemplate>
                                    <InsertItemTemplate>
                                        <div runat="server" id="repPCAT" class="show-check">
                                            <asp:Repeater runat="server" DataSource='<%#GetManagedPCATListWhenInserting() %>'>
                                                <ItemTemplate>
                                                    <div class="checkbox_class180">
                                                        <input type="radio" name="ReturnValue" value='<%#Eval("id")%>' />
                                                        <%#Eval("name")%>
                                                    </div>
                                                </ItemTemplate>
                                            </asp:Repeater>
                                        </div>
                                        <div id="dlPCAT" runat="server" class="show-check">
                                            Province (省):<select id="selectProvinces" name="SelectP">
                                                <option value="0">--请选择--</option>
                                                <asp:Repeater runat="server" DataSource='<%#GetProvinces() %>'>
                                                    <ItemTemplate>
                                                        <option value='<%#Eval("ProvinceID") %>'>
                                                            <%#Eval("Name") %></option>
                                                    </ItemTemplate>
                                                </asp:Repeater>
                                            </select>
                                            CAT (大客户):<select id="selectCategory" name="SelectC">
                                                <option value="0">--请选择--</option>
                                                <asp:Repeater runat="server" DataSource='<%#GetCategories() %>'>
                                                    <ItemTemplate>
                                                        <option value='<%#Eval("CateID") %>'>
                                                            <%#Eval("Name") %></option>
                                                    </ItemTemplate>
                                                </asp:Repeater>
                                            </select>
                                        </div>
                                    </InsertItemTemplate>
                                    <EditItemTemplate>
                                        <div runat="server" id="repPCAT" class="show-check">
                                            <asp:Repeater runat="server" DataSource='<%#GetManagedPCATList((int)Eval("CompanyID")) %>'>
                                                <ItemTemplate>
                                                    <div class="checkbox_class180">
                                                        <input type="radio" name="ReturnValue" value='<%#Eval("id")%>' <%#Eval("ischecked") %> />
                                                        <%#Eval("name")%>
                                                    </div>
                                                </ItemTemplate>
                                            </asp:Repeater>
                                        </div>
                                        <div id="dlPCAT" runat="server" class="show-check">
                                            Province (省):<select id="selectProvinces" name="SelectP" class="item-province" u="<%#GetProvince((int)Eval("CompanyID")) %>">
                                                <option value="0">--请选择--</option>
                                                <asp:Repeater runat="server" DataSource='<%#GetProvinces() %>'>
                                                    <ItemTemplate>
                                                        <option value='<%#Eval("ProvinceID") %>'>
                                                            <%#Eval("Name") %></option>
                                                    </ItemTemplate>
                                                </asp:Repeater>
                                            </select>
                                            Category (大客户):<select id="selectCategory" name="SelectC" class="item-category" u="<%#GetCategory((int)Eval("CompanyID")) %>">
                                                <option value="0">--请选择--</option>
                                                <asp:Repeater ID="Repeater1" runat="server" DataSource='<%#GetCategories() %>'>
                                                    <ItemTemplate>
                                                        <option value='<%#Eval("CateID") %>'>
                                                            <%#Eval("Name") %></option>
                                                    </ItemTemplate>
                                                </asp:Repeater>
                                            </select>
                                        </div>
                                    </EditItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Editor (编辑人)" AccessibleHeaderText="LastModifyBy">
                                    <ItemTemplate>
                                        <asp:Label ID="Label2" runat="server" Text='<%#Eval("LastModifyBy.NameEN")%>' />
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:Label runat="server" Text='<%# GetUser()%>' />
                                    </EditItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:Label runat="server" Text='<%# GetUser()%>' />
                                    </InsertItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField AccessibleHeaderText="AddCustomer" ShowHeader="false">
                                    <ItemTemplate>
                                        <input type="button" id="addcustomer" class="add-customer btn" value="Create a Customer"
                                            title="Create a customer (添加客户)" onclick="window.location.href='CustomerInfo.aspx?CompanyID=<%#Eval("CompanyID") %>'" />
                                        <input type="button" id="viewoc" style="display: <%#CheckOCShow((int)Eval("CompanyID"))%>"
                                            class="view-oc btn" value="Organization Chart" title="Organization Chart (组织关系图)"
                                            onclick="window.location.href='CustomerOC.aspx?CompanyID=<%#Eval("CompanyID") %>'" />
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                    </EditItemTemplate>
                                    <InsertItemTemplate>
                                    </InsertItemTemplate>
                                </asp:TemplateField>
                                <asp:ActionField ShowEditButton="true" ShowInsertButton="true" ShowInsertMoreButton="true"
                                    ShowCloseButton="true" ItemStyle-CssClass="entity-action2" />
                            </Fields>
                        </asp:DetailsView>
                        &nbsp;
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <%--以下是数据源--%>
    <asp:EntityDataSource ID="edsCompany" runat="server" ConnectionString="name=CCEntities"
        DefaultContainerName="CCEntities" EnableInsert="True" EnableUpdate="True" EntitySetName="Companies"
        Where="!it.Disabled" Include="LastModifyBy,PCATs,Countries" OnInserted="edsCompany_Inserted"
        OnUpdated="edsCompany_Updated">
    </asp:EntityDataSource>
    <asp:ObjectDataSource ID="odsCountryInCompany" runat="server" SelectMethod="GetCountryWithCompanyRelation"
        TypeName="ASBCC.Business.CIS.CompanyInfoHelper">
        <SelectParameters>
            <asp:ControlParameter ControlID="dvCompany" Name="companyID" PropertyName="DataKey.Value"
                Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:EntityDataSource ID="edsCountry" runat="server" ConnectionString="name=CCEntities"
        DefaultContainerName="CCEntities" EnableInsert="True" EnableUpdate="True" EntitySetName="Countries"
        Where="!it.Disabled">
    </asp:EntityDataSource>
    </div>
    </form>
    <%--页面刷新时显示--%>
    <%--    <div id="dialog-message" title="Loading..." style="display: none">
        <p>
            <br />
            <span class="entity-loading"></span><span>Operation in process, please wait...<br />
                <br />
                处理中, 请稍候。。。</span>
        </p>
    </div>--%>
</body>
</html>
